<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加添加岗位类型</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../css/oksub.css">
</head>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form">
        <div class="layui-form-item">
            <label class="layui-form-label">岗位类型</label>
            <div class="layui-input-block">
                <input type="text" name="typename" placeholder="请输入岗位类型" autocomplete="off" class="layui-input"
                       lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script src="../../lib/layui/layui.js"></script>
<script src="../../../../js/model.js"></script>
<script>
    layui.use(["element", "form", "laydate", "okLayer", "okUtils", "jquery"], function () {
        let form = layui.form;
        let laydate = layui.laydate;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;
        let $ = layui.jquery;


        // 获取contentText
        const ctx = function () {
            let pathName = document.location.pathname;
            let index = pathName.substr(1).indexOf("/");
            let result = pathName.substr(0, index + 1);
            return result;
        }();

        form.on("submit(add)", function (data) {
            var initData = data.field;
            var jobtype = new JobType(null, initData.typename);
            $.ajax({
                url: ctx + '/ygssecs/addjobtype',
                type: 'POST',
                data: {"jobtypejson": JSON.stringify(jobtype)},
                dataType: 'json',
                error: function () {
                    okLayer.redCrossMsg("服务器错误")
                },
                success: function (data) {
                    if (data.code == 200) {
                        // 业务正常
                        okLayer.greenTickMsg("添加成功", function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        });
                    } else {
                        // 业务异常
                        okLayer.yellowSighMsg(data.msg)
                    }
                }
            });
            return false;
        });

        function getAllProfession(success, error) {
            $.ajax({
                url: ctx + "/admin/getAllProfession",
                type: 'POST',
                headers: {"token": sessionStorage.getItem("token")},
            }).done(function (datas) {
                var list = datas['data'];
                var option;
                if (list.length != 0) {
                    for (var i = 0; i < list.length; i++) {
                        option += "<option value='" + list[i]['professionid'] + "'>" + list[i]['professionname'] + "</option>";//拼接option中的内容
                        $("#profession").html(option);//将option的拼接内容加入select中，注意选择器是select的ID
                    }
                }
                success();
                form.render('select');//重点：重新渲染select
            }).fail(function () {
                error();
                console.log("error");
            });
        }

        function getAllInstructor(success, error) {
            $.ajax({
                url: ctx + "/admin/getCounselorByIdAndName",
                type: 'POST',
                headers: {"token": sessionStorage.getItem("token")},
            }).done(function (datas) {
                var list = datas['data'];
                var option;
                for (var i = 0; i < list.length; i++) {
                    option += "<option value='" + list[i]['counselorId'] + "'>" + list[i]['counselorName'] + "</option>";//拼接option中的内容
                    $("#counselor").html(option);//将option的拼接内容加入select中，注意选择器是select的ID
                }
                success();
                form.render('select');//重点：重新渲染select
            }).fail(function () {
                console.log("error");
                error();
            });
        }
    });
</script>
</body>
</html>
